package com.life.notes.controller;

import com.life.notes.config.utils.BaseResponse;
import com.life.notes.config.utils.ResponseMsgUtil;
import com.life.notes.dto.PhoneQueryPara;
import com.life.notes.model.PhoneEntity;
import com.life.notes.service.PhoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p> 笔记管理-手机表  接口 </p>
 *
 * @author: zhengqing
 * @description:
 * @date: 2019-08-20
 *
 */
@RestController
@RequestMapping("/api/manual/phone")
@Api(description = "笔记管理-手机表 接口")
public class PhoneController {

    @Autowired
    PhoneService phoneService;

    @PostMapping(value = "/listPage", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取笔记管理-手机表 列表分页", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse listPage(@RequestBody PhoneQueryPara filter) {
        return ResponseMsgUtil.success(phoneService.listPage(filter));
    }

    @PostMapping(value = "/saveOrUpdate", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "保存或更新用户手机", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse saveOrUpdate(@RequestBody @Validated PhoneEntity input) {
        return ResponseMsgUtil.success(phoneService.savePhone(input));
    }

    @PostMapping(value = "/delete", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "删除用户手机号 ", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse delete(@RequestBody PhoneEntity input) {
        phoneService.removeById(input.getId());
        return ResponseMsgUtil.success("删除用户手机号成功");
    }

}
